package home4;

import org.junit.Test;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class test {
    @Test
    public  void  test1() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {
        Class<Person> ps = Person.class;
        Person s = ps.getConstructor(String.class, int.class).newInstance("s", 5);
        Method setName = ps.getDeclaredMethod("setName", String.class);

        setName.invoke(s,"张三");
        Field age = ps.getDeclaredField("age");
        age.setAccessible(true);
        age.set(s,15);
        System.out.println(s);
}}
